package kubayaxi.video.service.base.common.response;

import kubayaxi.video.service.base.common.enums.ResponseEnum;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @program: l_music
 * @description:
 * @author: Mr.lin
 * @create: 2022-09-01 17:29
 **/
@Getter
@Setter
public class ResponseResult<T> implements Serializable {
	private Integer code; // 状态码
	private String message; // 失败的错误提示
	private T data; // 成功后需要存放的数据
	
	public static ResponseResult<Void> success() {
		ResponseResult<Void> result = new ResponseResult<>();
		result.setCode(ResponseEnum.SUCCESS.getCode());
		result.setMessage(ResponseEnum.SUCCESS.getDescription());
		return result;
	}

	public static <T> ResponseResult<T> success(T data) {
		ResponseResult<T> result = new ResponseResult<>();
		result.setCode(ResponseEnum.SUCCESS.getCode());
		result.setMessage(ResponseEnum.SUCCESS.getDescription());
		result.setData(data);
		return result;
	}

	public static ResponseResult<Void> failed(String message) {
		ResponseResult<Void> result = new ResponseResult<>();
		result.setCode(ResponseEnum.FAILED.getCode());
		result.setMessage(message);
		return result;
	}

	public static ResponseResult<Void> failed() {
		ResponseResult<Void> result = new ResponseResult<>();
		result.setCode(ResponseEnum.FAILED.getCode());
		result.setMessage(ResponseEnum.FAILED.getDescription());
		return result;
	}

	public static ResponseResult<Void> failed(Integer code, String message) {
		ResponseResult<Void> result = new ResponseResult<>();
		result.setCode(code);
		result.setMessage(message);
		return result;
	}
}
